﻿using Common.Base;

using GameCommon.HitBoxes;
using GameCommon.ManagerInterfaces;
using GameCommon.ServiceInterfaces;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Moq;

namespace Common.Test.HitBoxes
{
    [TestClass]
    public class HexagonHitBoxTest
    {
        [TestMethod]
        public void Does_IsPointInHitbox_Work_Point_Outside()
        {
            TestHelper.SetupMock<IMouseManager>();
            TestHelper.SetupMock<IDrawingService>();

            var dimension = new Dimension(500, 200, 200, 180);

            var contentManager = TestHelper.SetupMock<IContentManager>();
            contentManager.Setup(x => x.GetRectangle(It.IsAny<Color>())).Returns((Texture2D)null);

            var hb = new HexagonHitBox(string.Empty, dimension, "Command");
            var point = new Position(600, 100);
            var result = hb.IsPointInHitbox(point);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void Does_IsPointInHitbox_Work_Point_In_TopLeft_Triangle()
        {
            TestHelper.SetupMock<IMouseManager>();
            TestHelper.SetupMock<IDrawingService>();
            var dimension = new Dimension(500, 200, 200, 180);

            var contentManager = TestHelper.SetupMock<IContentManager>();
            contentManager.Setup(x => x.GetRectangle(It.IsAny<Color>())).Returns((Texture2D)null);

            var hb = new HexagonHitBox(string.Empty, dimension, "Command");
            var point = new Position(510, 210);
            var result = hb.IsPointInHitbox(point);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void Does_IsPointInHitbox_Work_Point_In_TopRight_Triangle()
        {
            TestHelper.SetupMock<IMouseManager>();
            TestHelper.SetupMock<IDrawingService>();
            var dimension = new Dimension(500, 200, 200, 180);

            var contentManager = TestHelper.SetupMock<IContentManager>();
            contentManager.Setup(x => x.GetRectangle(It.IsAny<Color>())).Returns((Texture2D)null);

            var hb = new HexagonHitBox(string.Empty, dimension, "Command");
            var point = new Position(690, 210);
            var result = hb.IsPointInHitbox(point);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void Does_IsPointInHitbox_Work_Point_In_BottomLeft_Triangle()
        {
            TestHelper.SetupMock<IMouseManager>();
            TestHelper.SetupMock<IDrawingService>();
            var dimension = new Dimension(500, 200, 200, 180);

            var contentManager = TestHelper.SetupMock<IContentManager>();
            contentManager.Setup(x => x.GetRectangle(It.IsAny<Color>())).Returns((Texture2D)null);

            var hb = new HexagonHitBox(string.Empty, dimension, "Command");
            var point = new Position(510, 370);
            var result = hb.IsPointInHitbox(point);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void Does_IsPointInHitbox_Work_Point_In_BottomRight_Triangle()
        {
            TestHelper.SetupMock<IMouseManager>();
            TestHelper.SetupMock<IDrawingService>();
            var dimension = new Dimension(500, 200, 200, 180);

            var contentManager = TestHelper.SetupMock<IContentManager>();
            contentManager.Setup(x => x.GetRectangle(It.IsAny<Color>())).Returns((Texture2D)null);

            var hb = new HexagonHitBox(string.Empty, dimension, "Command");
            var point = new Position(690, 370);
            var result = hb.IsPointInHitbox(point);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void Does_IsPointInHitbox_Work_Point_In_Hexagon()
        {
            TestHelper.SetupMock<IMouseManager>();
            TestHelper.SetupMock<IDrawingService>();
            var dimension = new Dimension(500, 200, 200, 180);

            var contentManager = TestHelper.SetupMock<IContentManager>();
            contentManager.Setup(x => x.GetRectangle(It.IsAny<Color>())).Returns((Texture2D)null);

            var hb = new HexagonHitBox(string.Empty, dimension, "Command");
            var point = new Position(600, 300);
            var result = hb.IsPointInHitbox(point);

            Assert.IsTrue(result);
        }
    }
}